# (c) 2021 Copyright, Real-Time Innovations, Inc.  All rights reserved.
# RTI grants Licensee a license to use, modify, compile, and create derivative
# works of the software solely for use with RTI Connext DDS.  Licensee may
# redistribute copies of the software provided that all such copies are
# subject to this license. The software is provided "as is", with no warranty
# of any type, including any warranty for fitness for any purpose. RTI is
# under no obligation to maintain or support the software.  RTI shall not be
# liable for any incidental or consequential damages arising out of the use or
# inability to use the software.

cmake_minimum_required(VERSION 3.11)
project(rtiexamples-routing-service-monitor)
list(APPEND CMAKE_MODULE_PATH
    "${CMAKE_CURRENT_SOURCE_DIR}/../../../../resources/cmake/Modules"
)
include(ConnextDdsConfigureCmakeUtils)
connextdds_configure_cmake_utils()
find_package(RTIConnextDDS
    "6.1.1"
    REQUIRED
    COMPONENTS
        core
)
# Include ConnextDdsCodegen.cmake and ConnextDdsAddExample.cmakefrom resources/cmake
include(ConnextDdsCodegen)
include(ConnextDdsAddExample)

set(prefix "routing_service_monitoring")

connextdds_rtiddsgen_run(
    IDL_FILE "${CONNEXTDDS_DIR}/resource/idl/ServiceCommon.idl"
    LANG "C++11"
    OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/src"
    INCLUDE_DIRS "${CONNEXTDDS_DIR}/resource/idl"
    UNBOUNDED
)

connextdds_rtiddsgen_run(
    IDL_FILE "${CONNEXTDDS_DIR}/resource/idl/RoutingServiceMonitoring.idl"
    LANG "C++11"
    OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/src"
    INCLUDE_DIRS "${CONNEXTDDS_DIR}/resource/idl"
    UNBOUNDED
)

# This will help to ensure that all the files generated by codegen are
# created
add_custom_target(${prefix}_CXX11_sources
    DEPENDS
        ${ServiceCommon_CXX11_GENERATED_SOURCES} ${RoutingServiceMonitoring_CXX11_GENERATED_SOURCES}
)

set(obj_library ${prefix}_CXX11_obj)
add_library(${obj_library}
    OBJECT
    ${ServiceCommon_CXX11_SOURCES} ${RoutingServiceMonitoring_CXX11_SOURCES}
)

set(api "cpp2")
set(c_standard C_STANDARD 90)
set(cxx_standard CXX_STANDARD 11)

target_compile_definitions(
    ${obj_library}
    PRIVATE
    $<TARGET_PROPERTY:RTIConnextDDS::${api}_api,INTERFACE_COMPILE_DEFINITIONS>
)

target_include_directories(
    ${obj_library}
    PRIVATE
    $<TARGET_PROPERTY:RTIConnextDDS::${api}_api,INTERFACE_INCLUDE_DIRECTORIES>
)

set_target_properties(
    ${obj_library}
    PROPERTIES
        ${c_standard}
        ${cxx_standard}
)

add_dependencies(${obj_library}
    ${prefix}_CXX11_sources
)

set(subscriber_src
    "${CMAKE_CURRENT_SOURCE_DIR}/RoutingServiceMonitoring_subscriber.cxx"
)
# Add the target for the subscriber application
connextdds_add_application(
    TARGET "subscriber"
    LANG C++11
    SOURCES ${subscriber_src}
    PREFIX ${prefix}
    OUTPUT_NAME "RoutingServiceMonitoring_subscriber"
    SOURCES
        $<TARGET_OBJECTS:${prefix}_CXX11_obj>
        ${subscriber_src}
)
